package sctu.edu.java.year2016.team06.chenqiang.day20160522.chapter5_3;

/**
 * Created by XQ on 2016/5/22.
 * 编写java程序，创建二维数组arr[][],将二维数组所有元素的和输出。
 */
public class Chapter5_3 {
    public static void main(String[] args) {
        int arr[][] = {{8, 4, 0}, {5, 2, 0}, {7, 4, 0}};
        System.out.println("二维数组中的元素有：");
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println("");
        }
        System.out.println("二维数组中的所有元素的和为：");
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                sum = sum + arr[i][j];
            }
        }
        System.out.println(+sum);
    }
}

